- Provide examples for unit testing view controllers.
Appropriate aspects to test in View Controllers unit tests:
- Is
UILabeltext correct? - Is the number of
UITableViewrows correct? - Is
UIButtonenabled?
Inappropriate aspects to test in View Controllers unit tests:
UILabeltext color, font, and size.UITableViewbackground color.UIButtonautolayout constraints.
View controllers are considered testable if they are:
- Passive:
- They delegate actions to appropriate dependencies, such as a presenter or a view model.
- They focus solely on rendering the UI.
- Isolated from their dependencies:
- They don't directly retrieve data from the model.
- They aren't responsible for updating themselves based on the model.
MVVM and MVP are patterns that facilitate achieving these characteristics.